using System;
using System.Collections.Generic;
using System.Text;

namespace Lib.Extraction
{
    public class ToFlatData
    {
        public static void ExtractFlatToFile(string HTMLCode, string Separator)
        {
            string flatData = Utilities.CommonUtility.RemoveStrHtmlTags(HTMLCode,Separator,true);
            Utilities.FileUtility.SaveDataToRandomFile(flatData, AppDomain.CurrentDomain.BaseDirectory + "\\Files\\RAW\\");
            //string[] DataArray = flatData.Split(Separator.ToCharArray());
            //Utilities.FileUtility.SaveDataToRandomFile(String.Join(Separator,DataArray), AppDomain.CurrentDomain.BaseDirectory + "\\Files\\");
        }
        
        public static void ExtractFlatToFile(string HTMLCode, string Separator, string siteName)
        {
            //Get URL Information if there're
            string URL = "";
            string URLName = "";
            string[] URLContent = HTMLCode.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            if (URLContent.Length > 0)
            {
                URL = URLContent[0];
                
                if (URL.ToLower().IndexOf("http://") >= 0)
                {
                    HTMLCode = HTMLCode.Remove(0, HTMLCode.IndexOf(Environment.NewLine));
                    if (URLContent.Length > 1)
                    {
                        URLName = URLContent[1];
                        HTMLCode = HTMLCode.Remove(0, HTMLCode.IndexOf(Environment.NewLine));
                    }
                }
                else
                    URL = "";
                if (string.IsNullOrEmpty(URLName))
                    URLName = URL;
            }
            URLContent = null;
            string flatData = Utilities.CommonUtility.RemoveStrHtmlTags(HTMLCode, Separator, false);
            Utilities.FileUtility.SaveDataToRandomFile(URL + Environment.NewLine + URLName + Environment.NewLine + flatData, AppDomain.CurrentDomain.BaseDirectory + "\\Files\\RAW\\"+siteName+"\\");
            //string[] DataArray = flatData.Split(Separator.ToCharArray());
            //Utilities.FileUtility.SaveDataToRandomFile(String.Join(Separator,DataArray), AppDomain.CurrentDomain.BaseDirectory + "\\Files\\");
        }

        void GettingData()
        {
            
        }
    }
}
